﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DemountCIM.Framework.DataBase.Table
{
    public enum ProcessStage
    {
        无效,
        树脂板涂胶,
        树脂板安装,
        树脂板配重区,
        晶棒涂胶,
        晶棒安装,
        完成,
    }

    /// <summary>
    /// 过程数据
    /// </summary>
    [SugarTable("tb_process")]
    public class TbProcess
    {
        private object datalock = new object();

        public TbProcess()
        {
            Clear();
        }

        [SugarColumn(ColumnName = "id", IsIdentity = true, IsPrimaryKey = true)]
        public int Id { get; set; }

        [SugarColumn(ColumnName = "plate_id")]
        public string PlateID { get; set; }

        [SugarColumn(ColumnName = "glue_barcode_1")]
        public string GlueBarCode1 { get; set; }

        // 胶余量
        [SugarColumn(ColumnName = "glue_allowance_1")]
        public float GlueAllowance1 { get; set; }

        // 胶温度
        [SugarColumn(ColumnName = "glue_temperature_1")]
        public float GlueTemperature1 { get; set; }

        // 胶使用量
        [SugarColumn(ColumnName = "glue_dosage_1")]
        public float GlueDosage1 { get; set; }

        // 树脂板码信息
        [SugarColumn(ColumnName = "beam_barcode")]
        public string BeamBarCode { get; set; }

        [SugarColumn(ColumnName = "glue_barcode_2")]
        public string GlueBarCode2 { get; set; }

        [SugarColumn(ColumnName = "glue_allowance_2")]
        public float GlueAllowance2 { get; set; }

        [SugarColumn(ColumnName = "glue_temperature_2")]
        public float GlueTemperature2 { get; set; }

        [SugarColumn(ColumnName = "glue_dosage_2")]
        public float GlueDosage2 { get; set; }

        // 晶棒码信息
        [SugarColumn(ColumnName = "brick_barcode")]
        public string BrickBarCode { get; set; }

        // 入站时间
        [SugarColumn(ColumnName = "in_time")]
        public DateTime InTime { get; set; }

        // 出站时间
        [SugarColumn(ColumnName = "out_time")]
        public DateTime OutTime { get; set; }

        [SugarColumn(ColumnName = "stage")]
        public ProcessStage Stage { get; set; }

        public void Clear()
        {
            Id = 0;
            PlateID = string.Empty;
            GlueBarCode1 = string.Empty;
            GlueBarCode2 = string.Empty;
            GlueAllowance1 = 0;
            GlueAllowance2 = 0;
            GlueDosage1 = 0;
            GlueDosage2 = 0;
            GlueTemperature1 = 0;
            GlueTemperature2 = 0;
            BeamBarCode = string.Empty;
            InTime = DateTime.MinValue;
            OutTime = DateTime.MinValue;
            Stage = ProcessStage.无效;
            BrickBarCode = string.Empty;
        }

        /// <summary>
        /// 复制外部数据到本类
        /// </summary>
        public bool CopyFrom(TbProcess process)
        {
            if (null != process)
            {
                if (this == process)
                {
                    return true;
                }

                lock (datalock)
                {
                    Id = process.Id;
                    PlateID = process.PlateID;
                    GlueBarCode1 = process.GlueBarCode1;
                    GlueBarCode2 = process.GlueBarCode2;
                    GlueAllowance1 = process.GlueAllowance1;
                    GlueAllowance2 = process.GlueAllowance2;
                    GlueDosage1 = process.GlueDosage1;
                    GlueDosage2 = process.GlueDosage2;
                    GlueTemperature1 = process.GlueTemperature1;
                    GlueTemperature2 = process.GlueTemperature2;
                    BeamBarCode = process.BeamBarCode;
                    InTime = process.InTime;
                    Stage = process.Stage;
                    BrickBarCode = process.BrickBarCode;
                    OutTime = process.OutTime;
                }

                return true;
            }
            return false;
        }
    }
}
